﻿namespace OboutInc.SlideMenu.Designer
{
    using OboutInc.SlideMenu;
    using System;
    using System.Text;
    using System.Web.UI.Design;

    public sealed class SlideMenuDesigner : ControlDesigner
    {
        public override string GetDesignTimeHtml()
        {
            try
            {
                OboutInc.SlideMenu.SlideMenu component = (OboutInc.SlideMenu.SlideMenu) base.Component;
                if (component.MenuItems.Count == 0)
                {
                    return this.GetEmptyDesignTimeHtml();
                }
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < component.MenuItems.Count; i++)
                {
                    string str = (component.MenuItems[i].InnerHtml == string.Empty) ? ((component.MenuItems[i]._itemType == 0) ? "Parent" : "Child") : component.MenuItems[i].InnerHtml;
                    if (component.MenuItems[i]._itemType == 0)
                    {
                        builder.Append("<div style=\"border-left:1px solid A7A6AA;\"><div style=\"font:11px Tahoma; background-color:#EBE9ED; padding:3px; border-right:1px solid A7A6AA; border-bottom:1px solid A7A6AA; border-top:1px solid white; border-left:1px solid white;\">" + str + "</div></div>");
                    }
                    else
                    {
                        builder.Append("<div style=\"font:11px Tahoma; background-color:white; padding:5px; border-left:1px solid A7A6AA; border-right:1px solid A7A6AA; border-bottom:1px solid A7A6AA;\">" + str + "</div>");
                    }
                }
                return builder.ToString();
            }
            catch (Exception exception)
            {
                return this.GetErrorDesignTimeHtml(exception);
            }
        }

        protected override string GetEmptyDesignTimeHtml()
        {
            return base.CreatePlaceHolderDesignTimeHtml("Use <b>MenuItems</b> property to create menu.");
        }

        protected override string GetErrorDesignTimeHtml(Exception e)
        {
            return base.CreatePlaceHolderDesignTimeHtml(e.Message);
        }
    }
}

